#include "picture.h"

//得到左右上下数据
enum enumread fx(void)
{
    FILE *fp = fopen("/dev/input/event0","r+");
    struct input_event touchscreen;
    bool xnode = false;
    bool ynode = false;
    int x=0,y=0,x1=0,y1=0,n=0;
    enum enumread js;
    while(1)
    {
        bzero(&touchscreen,sizeof(touchscreen));
        fread(&touchscreen,1,sizeof(touchscreen),fp);
        if(touchscreen.type == EV_ABS)
        {
            if(touchscreen.code == ABS_X && x1 == 0)
            x1 = touchscreen.value;

            if(touchscreen.code == ABS_Y && y1 == 0)
            y1 = touchscreen.value;

            if(touchscreen.code == ABS_X && x1!=0)
            {
            x = touchscreen.value;
            xnode = true;
            }
            if(touchscreen.code == ABS_Y && y1!=0)
            {
            y = touchscreen.value;
            ynode = true;
            }            
            if(xnode && ynode)
            {
                if((x-x1)>100 && abs((y-y1))<50 && n==0)
                {
                    printf("右划\n");
                    n = 1;
                    return right;
                }
                else if((x1-x)>100 && abs((y-y1))<50 && n==0)
                {
                    printf("左划\n");
                    n = 1;
                    return left;                   
                }
                else if(abs(x-x1)<50 && (y1-y)>80 && n==0)
                {
                    printf("上划\n");
                    n = 1;
                    return up;                  
                }
                else if(abs(x-x1)<50 && (y-y1)>80 && n==0)
                {
                    printf("下划\n");
                    n = 1;
                    return down;                   
                }
                xnode = false;
                ynode = false;
            }  
        }
        if(touchscreen.type == EV_KEY)
        {
            if(touchscreen.value == 0)
            {
            x1 = 0;
            y1 = 0;
             n = 0;
            }
        }
    }
    fclose(fp);
}